﻿using MediatR;
using T_settlement.API.Application.Command.PayMoneyCommand;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.PayMoneyCommandHandlers
{
    public class PDelPayMoneyCommandHandlers:IRequestHandler<PDelPayMoneyCommand,int>
    {
        private readonly IPayMoneyRepository payMoneyRepository;

        public PDelPayMoneyCommandHandlers(IPayMoneyRepository payMoneyRepository)
        {
            this.payMoneyRepository = payMoneyRepository;
        }

        public async Task<int> Handle(PDelPayMoneyCommand request, CancellationToken cancellationToken)
        {
            var Id = request.PayMoneyId.Split(',').Select(x => Convert.ToInt32(x)).ToArray();
            var list = await payMoneyRepository.GetAsync(x => Id.Contains(x.PayMoneyId));
            foreach (var item in list)
            {
                item.IsDel = true;
            }
            return await payMoneyRepository.UpdateAsyncRange(list);
        }
    }
}
